home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / QuickDraw GX / QuickDraw GX Info / QuickDraw GX Interfaces / Interfaces & Libraries / graphics libraries / roundRect library.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-30  |  3.5 KB  |  96 lines  |  [TEXT/MPS ]

  1. /* graphics libraries
  2.     rounded corner gxRectangle routines
  3.     by Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  4.     Copyright 1987 - 1991 Apple Computer, Inc.  All rights reserved.    */
  5.  
  6. /************
  7.     Includes
  8. *************/
  9. #include "graphics libraries.h"
  10.  
  11. /*********
  12.     Code
  13. **********/
  14. static void RoundRectPath(Fixed *contourData, register const gxRectangle *r, const gxPoint *ovalSize)
  15. {
  16.     NilParamReturn(contourData);
  17.     NilParamReturn(r);
  18.     NilParamReturn(ovalSize);
  19.     {   register Fixed *contourWalker = contourData;
  20.         register Fixed offX = ovalSize->x/2;
  21.         register Fixed offY = ovalSize->y/2;
  22.         register Fixed maxX = (r->right - r->left) / 2;
  23.         register Fixed maxY = (r->bottom - r->top) / 2;
  24.         
  25.         if (offX > maxX)
  26.             offX = maxX;
  27.         if (offY >  maxY)
  28.             offY = maxY;
  29.         *contourWalker++ = 12;              /* twelve points, all in all            */
  30.         *contourWalker++ = 0x49200000;      /* one on, one off, one on... times 4       */
  31.     
  32.         *contourWalker++ = r->left;         /* 1st pt (top left corner)         */
  33.         *contourWalker++ = r->top + offY;
  34.         *contourWalker++ = r->left;         /* 2nd pt                           */
  35.         *contourWalker++ = r->top;
  36.         *contourWalker++ = r->left + offX;      /* 3rd pt                           */
  37.         *contourWalker++ = r->top;
  38.     
  39.         *contourWalker++ = r->right - offX;     /* 4th pt (top right corner)            */
  40.         *contourWalker++ = r->top;
  41.         *contourWalker++ = r->right;            /* 5th pt                           */
  42.         *contourWalker++ = r->top;
  43.         *contourWalker++ = r->right;            /* 6th pt                           */
  44.         *contourWalker++ = r->top + offY;
  45.     
  46.         *contourWalker++ = r->right;            /* 7th pt (bottom right corner)         */
  47.         *contourWalker++ = r->bottom - offY;
  48.         *contourWalker++ = r->right;            /* 8th pt                           */
  49.         *contourWalker++ = r->bottom;
  50.         *contourWalker++ = r->right - offX;     /* 9th pt                           */
  51.         *contourWalker++ = r->bottom;
  52.     
  53.         *contourWalker++ = r->left + offX;      /* 10th pt (bottom left corner)         */
  54.         *contourWalker++ = r->bottom;
  55.         *contourWalker++ = r->left;         /* 11th pt                      */
  56.         *contourWalker++ = r->bottom;
  57.         *contourWalker++ = r->left;         /* 12th pt                      */
  58.         *contourWalker++ = r->bottom - offY;
  59.     }
  60. }
  61.  
  62. gxShape NewRoundRect(const gxRectangle *rectData, const gxPoint *ovalSize)
  63. {
  64.     long newContour[26];
  65.  
  66.     NilParamReturnNil(rectData);
  67.     NilParamReturnNil(ovalSize);
  68.  
  69.     RoundRectPath(newContour, rectData, ovalSize);
  70.     return NewPath((gxPath *) newContour);
  71. }
  72.  
  73. void SetRoundRect(gxShape aShape, const gxRectangle *rectData, const gxPoint *ovalSize)
  74. {
  75.     long newContour[26];
  76.  
  77.     NilShapeReturn(aShape);
  78.     NilParamReturn(rectData);
  79.     NilParamReturn(ovalSize);
  80.  
  81.     RoundRectPath(newContour, rectData, ovalSize);
  82.     SetPath(aShape, 0, (gxPath *) newContour);
  83. }
  84.  
  85. void DrawRoundRect(const gxRectangle *bounds, const gxPoint *ovalSize, gxShapeFill fill)
  86. {   
  87.     NilParamReturn(bounds);
  88.     NilParamReturn(ovalSize);
  89.     {   register gxShape newShape = NewRoundRect(bounds, ovalSize);
  90.     
  91.         GXSetShapeFill(newShape, fill);
  92.         GXDrawShape(newShape);
  93.         GXDisposeShape(newShape);
  94.     }
  95. }
  96.